package com.yoj.questionservice.feign;

import com.yoj.questionservice.service.QuestionService;
import com.yoj.questionservice.service.QuestionSubmitService;
import com.yoj.model.entity.Question;
import com.yoj.model.entity.QuestionSubmit;
import com.yoj.serviceclient.service.question.QuestionFeignClient;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 题目服务内部调用接口，用来给其他服务远程调用的，不是给前端的
 */
@RestController()
@RequestMapping("/inner")
public class QuestionClient implements QuestionFeignClient {

    @Resource
    private QuestionService questionService;

    @Resource
    private QuestionSubmitService questionSubmitService;

    /**
     * 根据 id 查询题目
     * @param questionId 题目 id
     * @return 题目信息
     */
    @Override
    @GetMapping("/get/id")
    public Question getQuestionById(@RequestParam("questionId") long questionId) {
        return questionService.getById(questionId);
    }
    @Override
    @PostMapping("/question/update")
    public boolean updateQuestionById(@RequestBody Question question) {
        return questionService.updateById(question);
    }

    /**
     * 根据题目提交 id 查询题目提交
     * @param questionSubmitId 题目提交 id
     * @return 题目提交信息
     */
    @Override
    @GetMapping("/question_submit/id")
    public QuestionSubmit getQuestionSubmitById(@RequestParam("questionSubmitId") long questionSubmitId) {
        return questionSubmitService.getById(questionSubmitId);
    }

    /**
     * 根据题目提交 id 更新题目提交
     * @param questionSubmit 题目提交对象
     * @return 题目提交信息是否更新成功
     */
    @Override
    @PostMapping("/question_submit/update")
    public boolean updateQuestionSubmitById(@RequestBody QuestionSubmit questionSubmit) {
        return questionSubmitService.updateById(questionSubmit);
    }
}
